/**
 * 树的直径，裸题
 */
#include <bits/stdc++.h>
using namespace std;

#include <bits/extc++.h>
using namespace __gnu_pbds;


using llt = long long;
using Real = double;
using vi = vector<int>;

int N;
vector<vi> G;

int MxD, MxU;

void dfs(int u, int p, int d){
    if(MxD < d) {
        MxD = d;
        MxU = u;
    }
    for(auto v : G[u]){
        if(v == p) continue;

        dfs(v, u, d + 1);
    }
    return;
}

int proc(){
    MxD = MxU = 0;
    dfs(1, 0, 1);

    int r = MxU;
    MxD = MxU = 0;
    dfs(r, 0, 1);

    return MxD;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0);
    cin >> N;
    G.assign(N + 1, {});
    for(int a,b,i=1;i<N;++i){
        cin >> a >> b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    cout << proc() << "\n";
    return 0;
}